using System;
using System.Collections.Generic;
using System.Text;

namespace cb0tServer
{
    class Stats
    {
        public static ulong BytesReceived = 0;
        public static ulong BytesSent = 0;
        public static uint PublicMessagesReceived = 0;
        public static uint EmoteMessagesReceived = 0;
        public static uint PrivateMessagesReceived = 0;
        public static uint FailedLoginAttempts = 0;
        public static uint MuzzledUsers = 0;
        public static uint BannedUsers = 0;
        public static uint KickedUsers = 0;
        public static uint FloodedUsers = 0;
        public static uint UsersRejected = 0;
        public static uint UsersJoined = 0;
        public static uint UsersParted = 0;
        public static ushort PeakUserCount = 0;
        public static int udp_hits = 0;
        private static long StartTime = cb0tServer.Helpers.UnixTimeMS();

        public static void Clear()
        {
            BytesReceived = 0;
            BytesSent = 0;
            PublicMessagesReceived = 0;
            EmoteMessagesReceived = 0;
            PrivateMessagesReceived = 0;
            FailedLoginAttempts = 0;
            MuzzledUsers = 0;
            BannedUsers = 0;
            KickedUsers = 0;
            FloodedUsers = 0;
            UsersRejected = 0;
            UsersJoined = 0;
            UsersParted = 0;
            PeakUserCount = 0;
            udp_hits = 0;
            StartTime = cb0tServer.Helpers.UnixTimeMS();
        }

        public static String GetUptime()
        {
            long s1 = cb0tServer.Helpers.UnixTimeMS() - StartTime;

            int s = (int)Math.Round((double)s1 / 1000);

            if (s < 60) return "0 minutes";

            int m = (int)Math.Floor((double)s / 60);

            if (m < 60) return m + (m == 1 ? " minute" : " minutes");

            int h = (int)Math.Floor((double)m / 60);
            m -= (h * 60);

            if (h < 24) return h + (h == 1 ? " hour " : " hours ") + m + (m == 1 ? " minute" : " minutes");

            int d = (int)Math.Floor((double)h / 24);
            h -= (d * 24);

            return d + (d == 1 ? " day " : " days ") + h + (h == 1 ? " hour " : " hours ") + m + (m == 1 ? " minute" : " minutes");
        }

    }
}
